//
//  H5UrlManager.swift
//  GLUZSwift
//
//  Created by xyanl on 2025/3/7.
//  Copyright © 2025 考拉🐨. All rights reserved.
//

import UIKit

class H5UrlManager: NSObject {
    /// 首页
    static var homeH5Url: String {
        var url = SystemEnvManager.shared.forwarderUrl + "/pages/app/index?"
        switch UserProfile.identityId {
        case 2, 5, 6, 7, 8:
            url = SystemEnvManager.shared.forwarderUrl + "/pages/home/index?"
        default:
            break
        }
        return url + H5UrlManager.urlParameter()
    }
    
    /// 工作台
    static var wordH5Url: String {
        var url = SystemEnvManager.shared.shopUrl + "/pages/onlineWork/index?"
        switch UserProfile.identityId {
        case 8:
            url = SystemEnvManager.shared.forwarderUrl + "/pages/driverTask/index?"
            
        case 2, 5, 6, 7:
            url = SystemEnvManager.shared.forwarderUrl + "?"
            
        default:
            break
        }
        return url + H5UrlManager.urlParameter()
    }
    
    /// deepseek
    static var deepseekUrl: String {
        SystemEnvManager.shared.consignmentUrl + "/deepseek/index/index?" + H5UrlManager.urlParameter()
    }
    
    /// 加好友
    static var addFriendUrl: String {
        SystemEnvManager.shared.forwarderUrl + "/pages/allShippers/index?" + H5UrlManager.urlParameter()
    }
    
    /// 我的
    static var mineH5Url: String {
        SystemEnvManager.shared.shopUrl + "/pages/tabbar/newuser/index?" + H5UrlManager.urlParameter()
    }
    
    /// 购物车
    static func shoppingCarUrl(bId: String) -> String {
        SystemEnvManager.shared.shopUrl + "/pages/details/cart?" + H5UrlManager.urlParameter() + "&bid=" + bId
    }
    
    /// 商铺详情
    static func storeUrl(storeId: String) -> String {
        SystemEnvManager.shared.shopUrl + "/pages/details/merchantDetail?" + H5UrlManager.urlParameter() + "&bid=" + "\(storeId)"
    }
    
    
    /// 个人主页
    /// - Parameter id: 用户 id
    static func personalHomepage(_ userId: String) -> String {
        SystemEnvManager.shared.forwarderUrl + "/pages/myPersonPage/index?" + H5UrlManager.urlParameter() + "&targetUserId=" + userId
    }
    
    static func urlParameter(_ statusBarHeight: CGFloat = xIphoneStatusBarHeight, _ statusBottom: CGFloat = 0.0) -> String {
        let language = UserProfile.country == 0 ? "zh": "ru"
        let parameter: [String: Any] = [
            "token": UserProfile.token,
            "userId": UserProfile.userId,
            "lang": language,
            "mobile": UserProfile.mobile,
//            "identity_type": UserProfile.identityId,
            "statusBarHeight": statusBarHeight,
            "statusbottom": statusBottom,
            "version": Bundle.sg.appVersion, // 版本号
            "app": 1
        ]
        let queryString = parameter.toQueryString() ?? ""
        return queryString
    }
    
    /// 隐私政策
    static func privacyUrl(type: String) -> String {
        let url = SystemEnvManager.shared.shopUrl + "/pages/user/privacy/privacy?"
        let encodedString = type.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
        let language = LanguageManager.isLanguageZH ? "zh": "ru"
        let parameter: [String: Any] = [
            "lang": language,
            "statusBarHeight": xIphoneStatusBarHeight,
            "statusbottom": 0.0,
            "version": Bundle.sg.appVersion, // 版本号
            "app": 1,
            "type": encodedString
        ]
        return url + (parameter.toQueryString() ?? "")
    }
    
}
